/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.cardarus.operatingsystem.struts.forms;

import com.cardarus.operatingsystem.domain.ReminderType;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

import org.apache.struts.validator.ValidatorForm;

/**
 * This class holds information to create a new reminder.
 * @author Javier Snaider
 */
public class ReminderActionForm extends ValidatorForm {

    private DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
    private Date reminderDate;
    private String description;
    private String typeString;
    private String dateString;
    private ReminderType type;

    private String[] selectedRows = {};

 
    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param request The HTTP Request we are processing.
     * @return
     */
//    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
//        ActionErrors errors = new ActionErrors();
//        if (getDescription() == null || getDescription().length() < 1) {
//            errors.add("description", new ActionMessage("error.description.required"));
//        }
//        return errors;
//    }

    /**
     * @return the reminderDate
     */
    public Date getReminderDate() {
        return reminderDate;
    }

    /**
     * @param reminderDate the reminderDate to set
     */
    public void setReminderDate(Date reminderDate) {
        this.reminderDate = reminderDate;
    }

    /**
     * @return the description
     */
    public String getDescription() {
        return description;
    }

    /**
     * @param description the description to set
     */
    public void setDescription(String description) {
        this.description = description;
    }

    /**
     * @return the typeString
     */
    public String getTypeString() {
        return typeString;
    }

    /**
     * @param typeString the typeString to set
     */
    public void setTypeString(String typeString) {
        this.typeString = typeString;
        this.type = ReminderType.valueOf(typeString);
    }

    /**
     * @return the type
     */
    public ReminderType getType() {
        return type;
    }

    /**
     * @param type the type to set
     */
    public void setType(ReminderType type) {
        this.type = type;
    }

    /**
     * @return the dateString
     */
    public String getDateString() {
        return dateString;
    }

    /**
     * @param dateString the dateString to set
     */
    public void setDateString(String dateString) {
        this.dateString = dateString;
        try {
            this.reminderDate = df.parse(dateString);
        } catch (ParseException ex) {
            Logger.getLogger(ReminderActionForm.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * @return the selectedItems
     */
    public String[] getSelectedRows() {
        return selectedRows;
    }

    /**
     * @param selectedItems the selectedItems to set
     */
    public void setSelectedRows (String[] selectedItems) {
        this.selectedRows = selectedItems;
    }
}
